﻿using MobilesStore.Domain.Abstract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MobilesStore.Domain.Entities;

namespace MobilesStore.WebUI.Controllers
{
    public class CommentController : Controller
    {

        ICommentRepository repository;

        public CommentController(ICommentRepository repo)
        {
            this.repository = repo;
        }

        public void Save(Comment comment )
        {
            if (ModelState.IsValid)
            {
                repository.SaveComment(comment);
            }
        }

        public ViewResult AddComment(int productID)
        {
            Comment comment = new Comment();
            ViewBag.productID = productID;
            return View(comment);
        }

        [HttpPost]
        public ActionResult AddComment(Comment comment)
        {
            if (ModelState.IsValid)
            {
                repository.SaveComment(comment);
                return RedirectToAction("Detail", "Product", new { comment.ProductID});
            }
            else {
                ViewBag.productID = comment.ProductID;
                return View(comment);
            }
        }

        /*public ActionResult Index()
        {
            return View();
        }*/
    }
}
